package cn.com.dhcc.ddi.task.dao;

import cn.com.dhcc.app.core.dao.BaseDao;
import cn.com.dhcc.app.core.exception.DaoException;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.pub.CM;
import cn.com.dhcc.ddi.task.vo.TaskActiveLog;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

/**
 * @类: TaskActiveLogDao
 * @描述: TODO
 * @作者: 张洪涛
 * @日期: 2016年11月14日 下午4:01:57
 * @版权所有: 东华软件
 * @版本:1.0
 */
@Repository
public class TaskActiveLogDao extends BaseDao {
	private static Logger logger = Log.getLogger(LOGTYPE.DDI);

	/**
	 * @方法: getByTaskId
	 * @描述: 
	 * @param id
	 * @return
	 * @throws
	 */
	public TaskActiveLog getByTaskId(String taskId) throws DaoException{
		String msg;
		String sql = "select * from "+SI_TABLE("t_ddi_task_active_log")+" where task_id=?";
		try {
			return CM.getDao().getModule("获取任务运行时日志", sql,TaskActiveLog.class, new Object[]{taskId});
		} catch (DaoException e) {
			msg = "获取任务运行时日志失败";
			logger.error(msg, e);
			throw new DaoException(msg, e);
		}
	}
	/**
	 * 获取对象
	 * @param id
	 * @return
	 * @throws DaoException
	 */
	public TaskActiveLog get(String id) throws DaoException {
		return getDao().getModuleById("获取对象",TaskActiveLog.class,new Object[]{id});
	}
	/**
	 * 新增
	 * @param task
	 * @return
	 * @throws DaoException
	 */
	public int insert(TaskActiveLog obj) throws DaoException {
		return getDao().insertModule("新增",obj);
	}

	/**
	 * 修改
	 * @param task
	 * @return
	 * @throws DaoException
	 */
	public int update(TaskActiveLog obj) throws DaoException {
		return getDao().updateModuleByIdExecuteNull("修改",obj);
	}

	/**
	 * 新增或修改
	 * @param task
	 * @return
	 * @throws DaoException
	 */
	public int insertOrUpdate(TaskActiveLog obj) throws DaoException {
		return getDao().saveOrUpdateModuleByIdExecuteNull("新增或修改",obj);
	}
	
	public int deleteByTaskId(String taskId) throws DaoException {
		String sql = "DELETE FROM " + SI_TABLE("t_ddi_task_active_log") + " WHERE task_id=?";
		return getDao().delete("删除任务活动日志", sql, new Object[]{taskId});
	}
}
